package com.demo.dropdataack.service.common;


import com.alibaba.fastjson.JSONObject;
import com.demo.dropdataack.entity.Data;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

/**
 * @author mm
 */
public class DropAckHelper {


    private static  String url = "http://bts.travelsky.com/gateway/openApi/pullService/ack/bpm/v1";
    @Autowired
    private OkHttpClient okHttpClient ;

    /**
     * 下发航易行的数据
     * @return
     */
    public String  DropAck(String token ,String uuid){
        String bpmResponse = null;

        RequestBody body = new FormBody.Builder()
                .add("uuid", uuid)

                .build();

        MediaType JSON1 = MediaType.parse("application/text; charset=utf-8");
        Request.Builder getBpmRequest = new Request.Builder().url(url).post(body)
                .header("token", token).header("Content-Type","application/x-www-form-urlencoded");
        Call callBpm = okHttpClient.newCall(getBpmRequest.build());
        Response response = null;

        try {
            response = callBpm.execute();
            String data1 = response.body().string();
            Data data = JSONObject.parseObject(data1, Data.class);

            if (data.getCode() == null) {
                return null;
            }
             bpmResponse =data.getCode();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bpmResponse;
    }
}
